/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2022. All rights reserved.
 *
 * File Name     : roce_ad.h
 * Version       : v2.0
 * Created       : 2021/3/10
 * Description   : The definition of RoCE EXTRA function prototype, macros etc,. in kernel space.
 */

#ifndef ROCE_AD_H
#define ROCE_AD_H

#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) || (LINUX_VERSION_CODE == KERNEL_VERSION(4, 19, 90)) \
    || (LINUX_VERSION_CODE == KERNEL_VERSION(4, 18, 0)) || defined(OFED_MLNX_5_7_8) || defined(CENTOS8_2_4_18_0)
int roce3_post_recv(struct ib_qp *ibqp, const struct ib_recv_wr *wr, const struct ib_recv_wr **bad_wr);
int roce3_post_srq_recv(struct ib_srq *ibsrq, const struct ib_recv_wr *wr, const struct ib_recv_wr **bad_wr);
#else
int roce3_post_recv(struct ib_qp *ibqp, struct ib_recv_wr *wr, struct ib_recv_wr **bad_wr);
int roce3_post_srq_recv(struct ib_srq *ibsrq, struct ib_recv_wr *wr, struct ib_recv_wr **bad_wr);
#endif

void roce3_drain_rq(struct ib_qp *ibqp);

int roce3_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr, enum ib_srq_attr_mask attr_mask,
    struct ib_udata *udata);

int roce3_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *srq_attr);

struct ib_mr *roce3_get_dma_mr(struct ib_pd *ibpd, int access);
#if defined(FEATURE_ALLOC_MR_4)
struct ib_mr *roce3_alloc_mr(struct ib_pd *ibpd, enum ib_mr_type mr_type, u32 max_num_sg, struct ib_udata *udata);
#else
struct ib_mr *roce3_alloc_mr(struct ib_pd *ibpd, enum ib_mr_type mr_type, u32 max_num_sg);
#endif
struct ib_mr *roce3_reg_user_mr(struct ib_pd *ibpd, u64 start, u64 length, u64 virt_addr, int access,
    struct ib_udata *udata);

int roce3_map_kernel_frmr_sg(struct ib_mr *ibmr, struct scatterlist *sg, int sg_nents, unsigned int *sg_offset);


#endif // ROCE_AD_H